
--[[--
	*	
	*	文 件  :   proto.lua
 	*	功 能  :   设置 保存协议到槽  和 加载共享协议 
	*		
--]]--

local sprotoloader 	= require "sprotoloader"	--加载器
local sproto 		= require "sproto"
local game 		   	= require "proto.game"
local skynet		= require "skynet"


local loader = {
	
	GAME_TYPES = 0,
	GAME_C2S = 1,
	GAME_S2C = 2,	
}

--保存协议到槽中
function loader.init ()

	-- slot 0，1,2 set at main.lua
	sprotoloader.save(game.types, loader.GAME_TYPES)
	sprotoloader.save(game.c2s, loader.GAME_C2S)
	sprotoloader.save(game.s2c, loader.GAME_S2C)
end

-- Server -> Client
function loader.load (index)

--[[
	local host 		= sprotoloader.load (index):host "package"
	local request 	= host:attach (sprotoloader.load (index + 1))
	return host, request
]]--
	
	local host,request

	if index == loader.GAME_C2S then 

		host 		= sprotoloader.load (index+1):host "package"
		request 	= host:attach (sprotoloader.load (index))

	elseif index == loader.GAME_S2C then 

		host 		= sprotoloader.load (index-1):host "package"
		request 	= host:attach (sprotoloader.load (index))

	elseif index == loader.GAME_TYPES then 

		return 
	else end 

	return host, request			
	
end


return loader
